package com.androidx.p013lv.invention.adapter;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import com.androidx.p013lv.base.bean.VideoBean;
import com.androidx.p013lv.base.recycler.BaseRecyclerAdapter;
import com.androidx.p013lv.base.recycler.BaseRecyclerHolder;
import com.androidx.p013lv.base.utils.LogUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.invention.C1069R;
import com.androidx.p013lv.player.view.BrushVideoPlayer;
import com.google.android.exoplayer2.SeekParameters;
import java.lang.ref.WeakReference;
import p000a.shuyu.p005a.builder.GSYVideoOptionBuilder;
import p000a.shuyu.p005a.listener.GSYSampleCallBack;
import p000a.shuyu.p005a.utils.OrientationUtils;
import p000a.shuyu.p005a.video.StandardGSYVideoPlayer;
import p031tv.danmaku.ijk.media.exo2.Exo2PlayerManager;

/* renamed from: com.androidx.lv.invention.adapter.AdapterVideo */
public class AdapterVideo extends BaseRecyclerAdapter<VideoBean, Holder> {
    String domain;
    double height = ((double) ((UiUtils.getWindowWidth() * 9) / 16));
    int isPlay;
    BrushVideoPlayer.PlayerVideoInterface playerVideoInterface;
    private WeakReference<Activity> reference;

    public AdapterVideo(Activity activity, BrushVideoPlayer.PlayerVideoInterface playerVideoInterface2) {
        this.reference = new WeakReference<>(activity);
        this.playerVideoInterface = playerVideoInterface2;
    }

    public void setIsPlay(int i) {
        this.isPlay = i;
    }

    public void setDomain(String str) {
        this.domain = str;
    }

    public void MyHolder(Holder holder, int i) {
        holder.setData((VideoBean) this.list.get(i), i);
    }

    public void onViewRecycled(Holder holder) {
        super.onViewRecycled((RecyclerView.ViewHolder) holder);
        BrushVideoPlayer brushVideoPlayer = holder.player;
        if (brushVideoPlayer != null) {
            brushVideoPlayer.release();
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.Adapter
    public Holder onCreateViewHolder(ViewGroup viewGroup, int i) {
        return new Holder(LayoutInflater.from(viewGroup.getContext()).inflate(C1069R.C1074layout.item_video, viewGroup, false));
    }

    /* renamed from: com.androidx.lv.invention.adapter.AdapterVideo$Holder */
    public class Holder extends BaseRecyclerHolder {
        LinearLayout ll_video;
        private OrientationUtils orientationUtils;
        public BrushVideoPlayer player;
        RelativeLayout rl_ad;
        TextView tv_collect;
        TextView tv_number;
        TextView tv_share;

        public Holder(View view) {
            super(view);
            this.player = (BrushVideoPlayer) view.findViewById(C1069R.C1072id.play);
            this.tv_number = (TextView) view.findViewById(C1069R.C1072id.tv_number);
            this.tv_collect = (TextView) view.findViewById(C1069R.C1072id.tv_collect);
            this.tv_share = (TextView) view.findViewById(C1069R.C1072id.tv_share);
            this.tv_collect.setOnClickListener(this);
            this.tv_share.setOnClickListener(this);
            view.findViewById(C1069R.C1072id.tv_download).setOnClickListener(this);
            this.ll_video = (LinearLayout) view.findViewById(C1069R.C1072id.ll_video);
            this.rl_ad = (RelativeLayout) view.findViewById(C1069R.C1072id.rl_ad);
            final Activity activity = (Activity) AdapterVideo.this.reference.get();
            OrientationUtils orientationUtils2 = new OrientationUtils(activity, this.player);
            this.orientationUtils = orientationUtils2;
            orientationUtils2.setEnable(false);
            new GSYVideoOptionBuilder().setRotateViewAuto(false).setLockLand(false).setAutoFullWithSize(false).setShowFullAnimation(false).setIsTouchWiget(false).setVideoAllCallBack(new GSYSampleCallBack(AdapterVideo.this) {
                /* class com.androidx.p013lv.invention.adapter.AdapterVideo.Holder.C11331 */

                @Override // p000a.shuyu.p005a.listener.VideoAllCallBack, p000a.shuyu.p005a.listener.GSYSampleCallBack
                public void onAutoComplete(String str, Object... objArr) {
                    if (Holder.this.player.getBottomContainer() != null && Holder.this.player.getBottomContainer().getVisibility() == 0) {
                        Holder.this.player.getBottomContainer().setVisibility(8);
                    }
                    if (Holder.this.player.isIfCurrentIsFullscreen()) {
                        Holder.this.player.getFullWindowPlayer().startPlayLogic();
                    } else {
                        Holder.this.player.startPlayLogic();
                    }
                }

                @Override // p000a.shuyu.p005a.listener.VideoAllCallBack, p000a.shuyu.p005a.listener.GSYSampleCallBack
                public void onPrepared(String str, Object... objArr) {
                    super.onPrepared(str, objArr);
                    try {
                        if (Holder.this.player.getGSYVideoManager().getPlayer() instanceof Exo2PlayerManager) {
                            ((Exo2PlayerManager) Holder.this.player.getGSYVideoManager().getPlayer()).setSeekParameter(SeekParameters.NEXT_SYNC);
                        }
                    } catch (Exception unused) {
                        LogUtils.m63e("---->", "设置 seek 的临近帧");
                    }
                }

                @Override // p000a.shuyu.p005a.listener.VideoAllCallBack, p000a.shuyu.p005a.listener.GSYSampleCallBack
                public void onQuitFullscreen(String str, Object... objArr) {
                    super.onQuitFullscreen(str, objArr);
                    if (Holder.this.orientationUtils != null) {
                        Holder.this.orientationUtils.backToProtVideo();
                    }
                    if (Holder.this.player.getCurrentState() == 6 && Holder.this.player.getBottomContainer().getVisibility() == 0) {
                        Holder.this.player.getBottomContainer().setVisibility(8);
                    }
                }
            }).build((StandardGSYVideoPlayer) this.player);
            this.player.getFullscreenButton().setOnClickListener(new View.OnClickListener(AdapterVideo.this) {
                /* class com.androidx.p013lv.invention.adapter.AdapterVideo.Holder.View$OnClickListenerC11342 */

                public void onClick(View view) {
                    Holder.this.orientationUtils.resolveByClick();
                    Holder.this.player.startWindowFullscreen(activity, true, true);
                }
            });
            this.player.getBackButton().setOnClickListener(new View.OnClickListener(AdapterVideo.this) {
                /* class com.androidx.p013lv.invention.adapter.AdapterVideo.Holder.View$OnClickListenerC11353 */

                public void onClick(View view) {
                    if (Holder.this.orientationUtils != null) {
                        Holder.this.orientationUtils.backToProtVideo();
                    }
                }
            });
        }

        public void setData(VideoBean videoBean, int i) {
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.player.getLayoutParams();
            layoutParams.height = (int) AdapterVideo.this.height;
            if (i == 0) {
                layoutParams.topMargin = UiUtils.dp2px(16);
            } else {
                layoutParams.topMargin = 0;
            }
            this.player.setLayoutParams(layoutParams);
            if (videoBean.isAd()) {
                this.ll_video.setVisibility(8);
                this.rl_ad.setVisibility(0);
                videoBean.getAdInfoBean();
            } else {
                this.ll_video.setVisibility(0);
                this.rl_ad.setVisibility(8);
                TextView textView = this.tv_number;
                textView.setText(UiUtils.num2str(videoBean.getFakeWatchNum()) + "次播放");
                TextView textView2 = this.tv_collect;
                textView2.setText(UiUtils.num2str(videoBean.getFakeLikes()) + "");
                TextView textView3 = this.tv_share;
                textView3.setText(UiUtils.num2str(videoBean.getFakeShareNum()) + "");
                if (videoBean.isLikeBrush()) {
                    TextView textView4 = this.tv_collect;
                    textView4.setCompoundDrawablesWithIntrinsicBounds(textView4.getContext().getResources().getDrawable(C1069R.C1071drawable.ic_collect), (Drawable) null, (Drawable) null, (Drawable) null);
                } else {
                    TextView textView5 = this.tv_collect;
                    textView5.setCompoundDrawablesWithIntrinsicBounds(textView5.getContext().getResources().getDrawable(C1069R.C1071drawable.ic_collect_no), (Drawable) null, (Drawable) null, (Drawable) null);
                }
            }
            this.player.setVideoBean(videoBean, i, AdapterVideo.this.playerVideoInterface);
            if (AdapterVideo.this.isPlay == 1 && i == 0) {
                this.player.startPlayLogic();
                AdapterVideo.this.isPlay = 0;
                AdapterVideo.this.playerVideoInterface.click(this.player, videoBean, i, 0);
            }
        }

        private void resolveFullBtn(BrushVideoPlayer brushVideoPlayer) {
            brushVideoPlayer.startWindowFullscreen(this.tv_number.getContext(), true, true);
        }
    }
}
